package com.example.demo.mapper;


import com.example.demo.identity.Music;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MusicMapper {

    //    随机获取音乐
    @Select("select * from music order by RAND() limit 20")
    List<Music> randomMusic();

    //    通过音乐名称获取musicKey
    @Select("select music_key from music where music_name = #{music_name}")
    String findMusicByName(String music_name);

    //    获取用户喜欢的音乐列表
    @Select("select music_key, music_name, music_singer from userFavoritesMusic where user_id = #{uuId}")
    List<Music> getUserLikeList(String uuId);

    //    检查是否存在相同的喜欢的音乐信息
    @Select("select count(*) from userFavoritesMusic where user_id = #{userId} and music_key = #{musicKey}")
    int checkExists(@Param("userId") String userId, @Param("musicKey") String musicKey);

    //    添加喜欢的音乐信息
    @Insert("insert into userFavoritesMusic(user_id, music_key, music_name, music_singer)" +
            "values (#{userId}, #{musicKey},#{musicName},#{musicSinger})")
    int addFavorites(@Param("userId") String userId,
                     @Param("musicKey") String musicKey, @Param("musicName") String musicName, @Param("musicSinger") String musicSinger);

}
